--[[/**
-- * 
 * 泽塔将伤害转化为治疗量,平均治疗队友
-- *
-- */]]

---@class BuffEffect472100 : BaseBuffEffect
BuffEffect472100 = ClientFight.CreateClass("BuffEffect472100", ClientFight.BaseBuffEffect)
local t = BuffEffect472100

---@param fight Fight
---@param buff FighterBuff
function t:action(fight, buff, ...)
    local parameters = {...};
    local fightResult = parameters[3];
    local fighter = buff.target;
    local effectVal = buff.buffBean.f_BuffEffectValue;
    if (fightResult.damage <= 0) then
        return IBuffEffect.FAIL;
    end
    if (not AttackUtils.isDamage(fightResult.state)) then
        return IBuffEffect.FAIL;
    end

    targetFighters = fight.teams[fighter.teamIndex].fighters;
    local friends = {};
    for k, targetFighter in pairs(targetFighters) do
        if (targetFighter:isDie()) then
            goto continue;
        end
        if (targetFighter:isSummons()) then
            goto continue;
        end
        table.insert(friends, targetFighter);
        ::continue::
    end
    if (table.getn(friends) < 1) then
        return IBuffEffect.FAIL;
    end
    local addHp = (fightResult.damage * Utils.toRatio(effectVal[1]) / table.getn(friends));
    if (addHp < 1) then
        return IBuffEffect.FAIL;
    end
    for k, friend in pairs(friends) do
        DamageManager.setFighterHp(fight, friend, fighter, nil,
                DamageResultTypeEnum.HEAL, addHp, friend.hp + addHp, true, false, true);
        local logAddHp = addHp;
        SkillRoleMgr.savePathFile(string.format("[%s][EFFECT]Fighter %s Buff%s 伤害为%s,转化增加生命值%s,目标为%s",
                fight.frame, fighter.fighterId, buff.modelId, fightResult.damage, logAddHp, friend.fighterId
        ));
    end
    return ClientFight.BaseBuffEffect.action(self, fight, buff, ...);
end

t.New()